﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo

namespace Instrument.Ports
{
    /// <summary>
    /// DCB Flags 字段的完整标志位定义
    /// </summary>
    internal static class DcbFlags
    {
        #region 基础通信标志

        /// <summary>
        /// 启用二进制模式（必须设置为1）
        /// </summary>
        internal const uint F_BINARY = 0x00000001;

        /// <summary>
        /// 启用奇偶校验
        /// </summary>
        internal const uint F_PARITY = 0x00000002;

        /// <summary>
        /// XON/XOFF 输出流控制
        /// </summary>
        internal const uint F_OUTX = 0x00000100;

        /// <summary>
        /// XON/XOFF 输入流控制
        /// </summary>
        internal const uint F_INX = 0x00000200;

        /// <summary>
        /// 启用错误字符替换
        /// </summary>
        internal const uint F_ERRORCHAR = 0x00000400;

        /// <summary>
        /// 丢弃 NULL 字符（值为0的字符）
        /// </summary>
        internal const uint F_NULL = 0x00000800;

        /// <summary>
        /// 出错时中止读写操作
        /// </summary>
        internal const uint F_ABORTONERROR = 0x00004000;

        #endregion 基础通信标志

        #region DTR 控制标志（互斥，只能选一个）

        /// <summary>
        /// 禁用 DTR（数据终端就绪）线
        /// </summary>
        internal const uint F_DTRCONTROL_DISABLE = 0x00000000;

        /// <summary>
        /// 启用 DTR 线
        /// </summary>
        internal const uint F_DTRCONTROL_ENABLE = 0x00000010;

        /// <summary>
        /// DTR 握手流控制
        /// </summary>
        internal const uint F_DTRCONTROL_HANDSHAKE = 0x00000020;

        #endregion DTR 控制标志（互斥，只能选一个）

        #region RTS 控制标志（互斥，只能选一个）

        /// <summary>
        /// 禁用 RTS（请求发送）线
        /// </summary>
        internal const uint F_RTSCONTROL_DISABLE = 0x00000000;

        /// <summary>
        /// 启用 RTS 线
        /// </summary>
        internal const uint F_RTSCONTROL_ENABLE = 0x00001000;

        /// <summary>
        /// RTS 握手流控制
        /// </summary>
        internal const uint F_RTSCONTROL_HANDSHAKE = 0x00002000;

        /// <summary>
        /// RTS 切换模式（发送时启用，缓冲区满时禁用）
        /// </summary>
        internal const uint F_RTSCONTROL_TOGGLE = 0x00003000;

        #endregion RTS 控制标志（互斥，只能选一个）

        #region 硬件流控制标志

        /// <summary>
        /// CTS（清除发送）输出流控制
        /// </summary>
        internal const uint F_OUTXCTSFLOW = 0x00000004;

        /// <summary>
        /// DSR（数据设备就绪）输出流控制
        /// </summary>
        internal const uint F_OUTXDSRFLOW = 0x00000008;

        /// <summary>
        /// DSR 灵敏度：当 DSR 为低电平时忽略接收字符
        /// </summary>
        internal const uint F_DSRSENSITIVITY = 0x00000040;

        /// <summary>
        /// 当输入缓冲区满且发送了 XOFF 字符后继续发送
        /// </summary>
        internal const uint F_TXCONTINUEONXOFF = 0x00000080;

        #endregion 硬件流控制标志

        #region 组合标志（常用配置）

        /// <summary>
        /// 基本配置：二进制模式 + 无流控制
        /// </summary>
        internal const uint BASIC_CONFIG = F_BINARY;

        /// <summary>
        /// 软件流控制配置
        /// </summary>
        internal const uint SOFTWARE_FLOW_CONTROL = F_BINARY | F_INX | F_OUTX;

        /// <summary>
        /// 硬件流控制配置
        /// </summary>
        internal const uint HARDWARE_FLOW_CONTROL = F_BINARY | F_OUTXCTSFLOW | F_RTSCONTROL_HANDSHAKE;

        /// <summary>
        /// 标准串口配置（无流控制，启用DTR和RTS）
        /// </summary>
        internal const uint STANDARD_CONFIG = F_BINARY | F_DTRCONTROL_ENABLE | F_RTSCONTROL_ENABLE;

        #endregion 组合标志（常用配置）
    }
}